const Koa = require("koa");
const KoaRouter = require("@koa/router")
const bodyParser = require('koa-bodyparser');
const app = new Koa();
const router = new KoaRouter({
    prefix:"/damu"
});


router.get('/test', (ctx, next) => {
    console.log(1)
    ctx.body = {test:"test"}
    next()
},(ctx,next)=>{
    console.log(2)
    ctx.body.test2 = "test2"
    next()
},(ctx)=>{
    console.log(3)
    ctx.body.test3 = "test3"
});

router.put('/test', (ctx, next) => {
    ctx.body = "test-put"
});
router.patch('/test', (ctx, next) => {
    ctx.body = "test-put"
});



router.post('/a/:id', (ctx, next) => {
    console.log(ctx.query);
    console.log(ctx.params);
    console.log(ctx.request.body);
    console.log(ctx.headers.damu);

    ctx.body = "a-post"
});

app.use(bodyParser()); //必须提前注册
app.use(router.routes()).use(router.allowedMethods());
app.listen(8080)
